from Crypto.Cipher import AES
import base64


def add_to_16(s):
    while len(s) % 16 != 0:
        s += (16 - len(s) % 16) * chr(16 - len(s) % 16)
    return str.encode(s)


def get_secret(text, key='a5iQdZkW42vk07Te'):
    aes = AES.new(str.encode(key), AES.MODE_ECB)
    encrypted_text = str(base64. encodebytes(aes.encrypt(add_to_16(text))), encoding='utf8').replace('\n', '')
    return encrypted_text


def get_real_password(pwd, key):
    aa = pwd.split('/')
    aaa = len(aa)
    bbb = aa[aaa - 1].split('.')
    ccc = bbb[0]
    secret_text = get_secret(ccc, key=key)
    return pwd.replace(ccc, secret_text)


if __name__ == '__main__':
    password = '123456'
    key = 'rMbQyTY8td3Qxtnn'
    url = get_real_password(password, key=key)
    print(url)